function [correl_dX_m_n,covar_dX_m_n,std_dX_m,std_dX_n] = CalcTimeSeriesCorr1(X,prob_X,Phi_X,m,n,...
    Phi_X_m,Phi_X_n)
% computes corr(X(t+m)-X(t),X(t+m+n)-X(t+m))
    
    if nargin<=5
        Phi_X_m = mpower2(Phi_X,m);
    end
    
    if nargin<=6
        Phi_X_n = mpower2(Phi_X,n);
    end
    
    mean_X = sum(prob_X(:).*X(:));
    var_X = sum(prob_X(:).*(X(:).^2)) - mean_X^2;
    
    condE_X_m = Phi_X_m*X(:);
    condE_X_n = Phi_X_n*X(:);
    var_dX_m = 2*var_X - 2*(sum(prob_X(:).*X(:).*condE_X_m) - mean_X^2);
    var_dX_n = 2*var_X - 2*(sum(prob_X(:).*X(:).*condE_X_n) - mean_X^2);
    
    std_dX_m = sqrt(var_dX_m);
    std_dX_n = sqrt(var_dX_n);
    
    covar_term1 = sum(prob_X(:).*X(:).*(condE_X_n - X(:)));
    covar_term2 = sum(prob_X(:).*X(:).*(Phi_X_m*(condE_X_n - X(:))));
    covar_dX_m_n = covar_term1 - covar_term2;
    
    correl_dX_m_n = covar_dX_m_n/(std_dX_m*std_dX_n);


end